home *** CD-ROM | disk | FTP | other *** search
/ Internet Info 1994 March / Internet Info CD-ROM (Walnut Creek) (March 1994).iso / networking / ip / ka9q / osrc.arc / DRTEST.C < prev    next >
Encoding:
C/C++ Source or Header  |  1988-05-23  |  2.7 KB  |  106 lines

  1. #define    BASE 0x380
  2. #define    CTL     (BASE+0)
  3. #define    DATA    (BASE+1)
  4.  
  5. #define    KEYUP    105    /* Keyup delay: 105 bytes = 15 ms */
  6. #define    TAIL    3    /* TX release delay */
  7.  
  8. char isat;
  9.  
  10. #include <stdio.h>
  11. #include "8530.h"
  12. #ifndef    foo
  13. char buf[7000] = "Testing de KA9Q, Warren, NJ, using 56kbps MSK modem by WA4DSY";
  14. #else
  15. char buf[7000];
  16. #endif
  17.  
  18. main()
  19. {
  20.     register int i;
  21.  
  22.     /* Reset and Initialize 8530 channel B */
  23.     write_sio(CTL,R9,FHWRES);
  24.     write_sio(CTL,R4,X1CLK|SDLC|SYNC_ENAB);
  25.     write_sio(CTL,R1,0); /* Disable interrupts */
  26.     write_sio(CTL,R3,Rx8|RxCRC_ENAB|RxENABLE);
  27.     write_sio(CTL,R5,DTR|Tx8|TxENAB|TxCRC_ENAB);
  28.     write_sio(CTL,R7,FLAG);
  29.     write_sio(CTL,R9,0);    /* Interrupt bits off */
  30.     write_sio(CTL,R10,CRCPS|NRZ);    /* NRZ mode */
  31.     write_sio(CTL,R11,RCTRxCP|TCRTxCP); /* RxCLK = TRxCLK, TxCLK = RTxCLK */
  32.     write_sio(CTL,R0,RES_EOM_L);    /* Clear end-of-message flag */
  33.  
  34.     txon();
  35.     for(i=0;i<7;i++)
  36.         send_buf(buf,sizeof(buf));
  37.     txoff();
  38. }
  39. /* Transmit a buffer. The transmitter must already be on. */
  40. send_buf(buf,n)
  41. register char *buf;
  42. register unsigned int n;
  43. {
  44.     write_sio(CTL,R0,RES_Tx_CRC);    /* Restart TX CRC calculation */
  45.  
  46.     /* Send data bytes */
  47.     outportb(DATA,*buf++);
  48.     n--;
  49.     write_sio(CTL,R0,RES_EOM_L);    /* Clear end-of-message flag */
  50.     while(n-- != 0){
  51.         while(!(read_sio(CTL,R0) & Tx_BUF_EMP))
  52.             ;
  53.         outportb(DATA,*buf++);
  54.     }
  55.     /* Wait for tx buffer empty to drop to indicate CRC going out */
  56.     while(read_sio(CTL,R0) & Tx_BUF_EMP)
  57.         ;
  58.     /* Now wait for the transmitter to become ready again,
  59.      * once CRC finishes
  60.      */
  61.     while(!(read_sio(CTL,R0) & Tx_BUF_EMP))
  62.         ;
  63. }
  64. /* Turn on transmitter and wait for keyup delay. This is done by
  65.  * starting a garbage frame, sending enough characters to allow
  66.  * for the delay, and then aborting it.
  67.  */
  68. txon()
  69. {
  70.     register int i;
  71.  
  72.     /* Turn on transmitter */
  73.     write_sio(CTL,R5,DTR|Tx8|TxENAB|TxCRC_ENAB|RTS);
  74.  
  75.     /* Send dummy frame */
  76.     for(i=KEYUP;i != 0; i--){
  77.         while(!(read_sio(CTL,R0) & Tx_BUF_EMP))
  78.             ;
  79.         outportb(DATA,'\0');
  80.     }
  81.     /* Now abort it */
  82.     write_sio(CTL,R0,SEND_ABORT);
  83. }
  84. /* Turn off transmitter. First start a new dummy frame to allow the last
  85.  * data frame to get out, then abort it.
  86.  */
  87. txoff()
  88. {
  89.     register int i;
  90.  
  91.     /* Wait in case a CRC is just going out */
  92.     while(!(read_sio(CTL,R0) & Tx_BUF_EMP))
  93.             ;
  94.     write_sio(CTL,R0,RES_Tx_CRC);    /* Restart TX CRC calculation */
  95.     write_sio(CTL,R0,RES_EOM_L);    /* Clear end-of-message flag */
  96.     /* Send dummy frame */
  97.     for(i=TAIL;i != 0; i--){
  98.         while(!(read_sio(CTL,R0) & Tx_BUF_EMP))
  99.             ;
  100.         outportb(DATA,'\0');
  101.     }
  102.     write_sio(CTL,R0,SEND_ABORT);            /* Abort frame */
  103.     write_sio(CTL,R5,DTR|Tx8|TxENAB|TxCRC_ENAB);    /* Drop carrier */
  104. }
  105.  
  106.